package 包含min函数的栈;

import java.util.LinkedList;

/**
 * 辅助栈的特性
 */
public class MinStackV2 {

    private LinkedList<Integer> dataStack;
    private LinkedList<Integer> minStack;
    /** initialize your data structure here. */
    public MinStackV2() {
        dataStack = new LinkedList<>();
        minStack = new LinkedList<>();
    }
    public void push(int x) {
        if(minStack.isEmpty() || minStack.peek() > x){
            minStack.push(x);
        }else{
            minStack.push(minStack.peek());
        }
        dataStack.push(x);
    }

    public void pop() {
        minStack.pop();
        dataStack.pop();
    }

    public int top() {
        return dataStack.peek();
    }

    public int min() {
        return minStack.peek();
    }

    public void printSnapshot() {
        System.out.println("dataStack: " + dataStack.toString());
        System.out.println("minStack: " + minStack.toString());
    }
}
